﻿using System;
using System.Diagnostics;
using System.Reflection;
using static ReflectAndMetadata.DynimcDelegate;

namespace ReflectAndMetadata
{
    class Program
    {
        static void Main(string[] args)
        {
            //TypeSample typeSample = new TypeSample();
            //typeSample.GetMetaData();

            //Type t = Assembly.GetExecutingAssembly().GetType("ReflectAndMetadata.TypeSample");
            //Console.WriteLine(t);

            //Type t2 = Type.GetType("System.Int32, System.Private.CoreLib");
            //Console.WriteLine(t2);



            //GetNestedTypes();

            //ShowTypeName();

            //ShowNestedTypeName();

            //ShowGenericTypeName();

            //TestRefMethod();

            //ShowBaseTypeAndInterface();

            //测试生成实例
            // TestInstantingType();

            /*
            *测试动态生成委托的实例
            **/
            //TestDynamicDelegate();

            /*
            *测试MemberInfo
            */
            //TestMemberInfo();

            /*
             *测试GetMethod
             */
            //TestGetMethod();
            /*
            *测试泛型成员信息
            */
            //TestGenericMembers();
            /*
              *测试动态调用
            */
            //TestDynamicInvoke();
            /*
             *测试方法参数
            */
            TestDynamicInvokeMethodParameters();


        }

        static void GetNestedTypes()
        {
            foreach (TypeInfo t in typeof(System.Environment).GetTypeInfo()
                                                     .DeclaredNestedTypes)
                Debug.WriteLine(t.FullName);
        }

        static void ShowTypeName()
        {
            TypeNameTest typeNameTest = new TypeNameTest();
            typeNameTest.ShowTypeFullName();
        }

        static void ShowNestedTypeName()
        {
            TypeNameTest typeNameTest = new TypeNameTest();
            typeNameTest.ShowNestedTypeName();
        }

        static void ShowGenericTypeName()
        {
            TypeNameTest typeNameTest = new TypeNameTest();
            typeNameTest.ShowGenericTypaName();
        }

        static void TestRefMethod()
        {
            TypeNameTest typeNameTest = new TypeNameTest();
            int a = 100;
            typeNameTest.RefMethod(ref a);
        }

        static void ShowBaseTypeAndInterface()
        {
            BaseTypeAndInterfaces baseTypeAndInterfaces = new BaseTypeAndInterfaces();
            baseTypeAndInterfaces.ShowBaseTypeAndInterFace();
        }

        static void TestInstantingType()
        {
            InstantingTypes instantingTypes = new InstantingTypes();
            instantingTypes.TestActivator();
            instantingTypes.TestActivatorWithParam();
        }

        static void TestDynamicDelegate()
        {
            Type type = typeof(IntFunc);
            Delegate d1 = Delegate.CreateDelegate(type, typeof(DynimcDelegate), "Square");

            Delegate d2 = Delegate.CreateDelegate(type, new DynimcDelegate(), "Cube");

            Console.WriteLine(d1.DynamicInvoke(0));
            Console.WriteLine(d2.DynamicInvoke(5));
        }

        static void TestMemberInfo()
        {
            ReflectMemberInfo reflectMemberInfo = new ReflectMemberInfo();
            reflectMemberInfo.ShowMemberInfo();
        }

        static void TestGetMethod()
        {
            ReflectMemberInfo reflectMemberInfo = new ReflectMemberInfo();
            reflectMemberInfo.GetMethod();
        }

        static void TestGenericMembers()
        {
            ReflectMemberInfo reflectMemberInfo = new ReflectMemberInfo();
            reflectMemberInfo.GetGenericTypeMember();
        }

        static void TestDynamicInvoke()
        {
            ReflectMemberInfo reflectMemberInfo = new ReflectMemberInfo();
            reflectMemberInfo.DynamicInvokeMember();
        }

        static void TestDynamicInvokeMethodParameters()
        {
            ReflectMemberInfo reflectMemberInfo = new ReflectMemberInfo();
            reflectMemberInfo.DynamicInvokeMethodParameters();
        }
    }
}
